package flc.ast.utils;

import android.content.res.AssetFileDescriptor;
import android.media.MediaPlayer;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.Utils;

import stark.common.basic.media.audio.AudioPlayerImpl;

/**
 * Author：daizhongbin on 2023/8/24
 * Email：1027154338@qq.com
 * Desc:
 */
public class MyAudioPlayer extends AudioPlayerImpl {

    private static MyAudioPlayer sInstance;

    private MyAudioPlayer() {

    }

    public synchronized static MyAudioPlayer getInstance() {
        if (sInstance == null) {
            sInstance = new MyAudioPlayer();
        }
        return sInstance;
    }

    public void play() {
        play(new ISourceLoader() {
            @Override
            public void onLoadSource(@NonNull MediaPlayer mediaPlayer) {
                try {
                    AssetFileDescriptor afd = Utils.getApp().getAssets().openFd("y2055.mp3");
                    mediaPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
                    mediaPlayer.setLooping(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    @Override
    protected boolean needUpdateTime() {
        return false;
    }

    @Override
    protected boolean needListenAppStatusChanged() {
        return true;
    }
}
